package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.project.api.domain.simple.ProjectTimeSimple;
import com.nbsaas.boot.project.data.entity.ProjectTime;
import com.nbsaas.boot.rest.api.Converter;

/**
 * 项目计时-列表对象转换器
 */

public class ProjectTimeSimpleConvert implements Converter<ProjectTimeSimple, ProjectTime> {


    @Override
    public ProjectTimeSimple convert(ProjectTime source) {
        ProjectTimeSimple result = new ProjectTimeSimple();

        result.setNote(source.getNote());
        result.setUsedTime(source.getUsedTime());

        try {
            if (source.getCreator() != null) {
                result.setCreator(source.getCreator().getId());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getCreator() != null) {
                result.setCreatorName(source.getCreator().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getProject() != null) {
                result.setProject(source.getProject().getId());
            }
        } catch (Exception ignored) {
        }

        result.setRecordDate(source.getRecordDate());
        result.setId(source.getId());

        try {
            if (source.getProject() != null) {
                result.setProjectName(source.getProject().getName());
            }
        } catch (Exception ignored) {
        }

        result.setAddDate(source.getAddDate());
        result.setLastDate(source.getLastDate());


        return result;
    }

}